/*
 * Settings.h
 *
 *  Created on: 30.04.2009
 *      Author: h3llfire
 */

#ifndef SETTINGS_H_
#define SETTINGS_H_

#include "../database/DBModule.h"
#include <vector>

namespace Impp {


enum TextSettingFlag{
	TEXT_SETTING_NORMAL,
	TEXT_SETTING_PASSWORD
};

class ChooseSetting;
class Settings;
class SettingsGroup;
class SettingsPage;

class Setting{

protected:
	wxString name;
	wxString description;
	SettingsPage* page;

	Setting(SettingsPage* page, const wxString & name, const wxString & description) :
		name(name), description(description), page(page){};
public:
	virtual ~Setting() {};

	const wxString& getSettingName() const{ return name; };
	const wxString& getLabel() const{ return description; };
	DBModule& getModule();
};

class ChooseSettingPair{

friend class ChooseSetting;

private:
	wxString value;
	wxString label;

	ChooseSettingPair(const wxString & value, const wxString & label) :
		value(value), label(label){};

public:
	virtual ~ChooseSettingPair() {};

	const wxString& getLabel() const{ return label; };
	const wxString& getValue() const{ return value; };
};

class ChooseSetting : public Setting{

friend class SettingsGroup;

private:
	std::vector<ChooseSettingPair> choices;

	ChooseSetting(SettingsPage* page, const wxString & name, const wxString & description) :
		Setting(page, name, description){};
	virtual ~ChooseSetting() {};

public:
	void addChoice(const wxString & value, const wxString & label){
		choices.push_back(ChooseSettingPair(value, label));
	}

	std::vector<ChooseSettingPair> getChoises(){
		return choices;
	}
};

class CheckSetting : public Setting{

	friend class SettingsGroup;

	CheckSetting(SettingsPage* page, const wxString & name, const wxString & description) :
			Setting(page, name, description){};
	virtual ~CheckSetting() {};
};

class TextSetting : public Setting{

	friend class SettingsGroup;

	int/*<TextSettingFlag>*/ flags;

	TextSetting(SettingsPage* page, const wxString & name, const wxString & description) :
			Setting(page, name, description){};
	virtual ~TextSetting() {};
};

class SettingsGroup{

	friend class SettingsPage;

private:
	SettingsPage* page;
	wxString label;
	std::vector<Setting*> settings;

	SettingsGroup(SettingsPage* page, const wxString & label) :
		page(page),label(label){};
	virtual ~SettingsGroup(){
		std::vector<Setting*>::iterator i(settings.begin());
		while(i != settings.end()){
			delete *i;
			i++;
		}
	}

public:
	TextSetting* createTextSetting(const wxString & label, const wxString & settingName, int/*<TextSettingFlag>*/ flags){
		TextSetting* s = new TextSetting(page, settingName, label);
		settings.push_back(s);
		return s;
	};
	CheckSetting* createCheckSetting(const wxString & label, const wxString & settingName){
		CheckSetting* s = new CheckSetting(page, settingName, label);
		settings.push_back(s);
		return s;
	};
	ChooseSetting* createChooseSetting(const wxString & label, const wxString & settingName){
		ChooseSetting* s = new ChooseSetting(page, settingName, label);
		settings.push_back(s);
		return s;
	};

	std::vector<Setting*> getSettings(){
		return settings;
	}

	const wxString& getLabel(){ return label; };
};

class SettingsPage{

	friend class Settings;

private:
	wxString label;
	DBModule module;
	std::vector<SettingsGroup*> groups;

	SettingsPage(const wxString & label,const DBModule & module):
		label(label),
		module(module){};
public:
	virtual ~SettingsPage(){
		std::vector<SettingsGroup*>::iterator i(groups.begin());
		while(i != groups.end()){
			delete *i;
			i++;
		}
	}

public:
	const wxString& getLabel(){ return label; };
	DBModule& getDBModule(){ return module; };

public:
	SettingsGroup* createSettingsGroup(const wxString & label){
		SettingsGroup* g = new SettingsGroup(this, label);
		groups.push_back(g);
		return g;
	};

	std::vector<SettingsGroup*> getSettingsGroups(){
		return groups;
	}
};

class Settings {

private:
	std::vector<SettingsPage*> pages;

public:
	Settings();
	virtual ~Settings(){
		std::vector<SettingsPage*>::iterator i(pages.begin());
		while(i != pages.end()){
			delete *i;
			i++;
		}
	};

	SettingsPage* createSettingsPage(const DBModule & module,const wxString & title){
		SettingsPage* page = new SettingsPage(title, module);
		pages.push_back(page);
		return page;
	};

	std::vector<SettingsPage*> getSettingPages() const{
		return pages;
	}

};

}

#endif /* SETTINGS_H_ */
